package com.xxx.common.model;

import com.xxx.json.GsonUtil;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;

import java.io.Serializable;

@Data
@JsonIgnoreProperties(ignoreUnknown=true)
@Slf4j
public class BaseWrapper<T> implements Serializable {

	private static final long serialVersionUID = 1L;
	
	private int code=0;
	private String message="";
	private T entity;



	public static BaseWrapper<Integer> SUCCESS  = new BaseWrapper<Integer>();

	public BaseWrapper(){
		this(RespEnum.SUCCESS);
	}

	public BaseWrapper(RespEnum bw){
		this(bw.getCode(),bw.getDesc());
	}

	public BaseWrapper(RespEnum bw, String message, T entity){
		this(bw.getCode(),message,entity);
	}

	public BaseWrapper(int code, String message) {
		this(code,message,null);
	}

	public BaseWrapper(RespEnum bw, String message){
		this(bw.getCode(),message);
	}

	public BaseWrapper(RespEnum bw, T entity){
		this(bw.getCode(), bw.getDesc(),entity);
	}


	/**
	 * 判断查询对象是否为null
	 * @param  entity;
	 */
	public  BaseWrapper(T entity) {
		this( RespEnum.SUCCESS.getCode(),RespEnum.SUCCESS.getDesc(),entity);
	}

	/**
	 * 判断查询对象是否为null
	 * @param  entity;
	 */
	public  BaseWrapper(int code,String message,T entity) {
		this.code = code;
		this.message = message;
		this.entity = entity;
		if(log.isInfoEnabled()){
			log.info(GsonUtil.GsonString(this));
		}
	}
}
